﻿// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI;
using Microsoft.Graphics.Canvas.UI.Xaml;
using System;
using System.Diagnostics;
using System.Numerics;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace ExampleGallery
{
    public sealed partial class SpriteSheets : UserControl
    {
        public bool ClampToSourceRect { get; set; }
        public bool TintSprites { get; set; }
        public bool ShowCollision { get; set; }

        bool rotateAndScale = false;
        public bool RotateAndScale
        {
            get { return rotateAndScale; }
            set { rotateAndScale = value; rotateAndScaleCounter = 0; }
        }

        public string InterpolationMode { get; set; }

        SpriteSheet forestTiles;
        SpriteSheet wizardWalk;
        SpriteSheet wizardIdle;

        enum Direction
        {
            Down,
            DownLeft,
            Left,
            UpLeft,
            Up,
            UpRight,
            Right,
            DownRight
        }

        static double[] directionAngles =
        {
            0.50 * Math.PI, // Down
            0.75 * Math.PI, // DownLeft
            1.00 * Math.PI, // Left
            1.25 * Math.PI, // UpLeft
            1.50 * Math.PI, // Up
            1.75 * Math.PI, // UpRight
            0.00 * Math.PI, // Right
            0.25 * Math.PI  // DownRight
        };

        Vector2 wizardPosition = new Vector2(3 * 64, 2 * 64);
        Direction wizardDirection = Direction.Down;
        int wizardCycle;
        int wizardTicks;

        Vector2 lastTouchedPoint;
        bool touched;

        Matrix3x2 transform = Matrix3x2.Identity;
        int rotateAndScaleCounter = 0;

        bool spriteBatchSupported;

        public SpriteSheets()
        {
            ClampToSourceRect = true;
            DataContext = this;
            InterpolationMode = CanvasImageInterpolation.Linear.ToString();

            mapHeight = baseLayer.Length / mapWidth;

            Debug.Assert(baseLayer.Length == fringeLayer.Length);
            Debug.Assert(baseLayer.Length == objectLayer.Length);
            Debug.Assert(baseLayer.Length == collisionLayer.Length);

            this.InitializeComponent();
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            FlyoutButton.Flyout.ShowAt(FlyoutButton);
        }

        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            // Explicitly remove references to allow the Win2D controls to get garbage collected
            canvas.RemoveFromVisualTree();
            canvas = null;
        }

        void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            spriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);

            if (!spriteBatchSupported)
                return;

            args.TrackAsyncAction(LoadImages(sender.Device).AsAsyncAction());
        }

        async Task LoadImages(CanvasDevice device)
        {
            forestTiles = await SpriteSheet.LoadAsync(device, "SpriteSheets/ForestTiles.png", new Vector2(64, 64), Vector2.Zero);
            wizardWalk = await SpriteSheet.LoadAsync(device, "SpriteSheets/WizardWalkRight.png", new Vector2(128, 192), new Vector2(64, 150));
            wizardIdle = await SpriteSheet.LoadAsync(device, "SpriteSheets/WizardIdleRight.png", new Vector2(128, 192), new Vector2(64, 150));
        }

        void OnControlPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint((UIElement)sender).Position.ToVector2();

            var action = canvas.RunOnGameLoopThreadAsync(() =>
            {
                lastTouchedPoint = point;
                touched = true;
            });
        }

        void OnControlPointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint((UIElement)sender).Position.ToVector2();

            var action = canvas.RunOnGameLoopThreadAsync(() =>
            {
                lastTouchedPoint = point;
            });
        }

        void OnControlPointerReleased(object sender, PointerRoutedEventArgs e)
        {
            var action = canvas.RunOnGameLoopThreadAsync(() =>
            {
                touched = false;
            });
        }


        void OnUpdate(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            if (!spriteBatchSupported)
                return;

            UpdateWizardCycle();

            // While the pointer is being held we move the wizard
            if (touched)
            {
                UpdateMovement();
            }

            if (RotateAndScale)
                rotateAndScaleCounter++;

            UpdateTransform(sender);
        }

        // Update the wizard's animation frame.  Fortunately, all the animations have 6 frames.
        // We wait a for a few update ticks before moving to the next animation frame (effectively
        // slowing down the animation).
        void UpdateWizardCycle()
        {
            const int wizardTicksPerCycle = 10;

            wizardTicks++;
            if (wizardTicks > wizardTicksPerCycle)
            {
                wizardCycle = (wizardCycle + 1) % 6;
                wizardTicks = 0;
            }
        }

        void UpdateMovement()
        {
            const float moveSpeed = 4;

            Matrix3x2 inverseTransform;
            if (!Matrix3x2.Invert(transform, out inverseTransform))
                return;

            // The wizard will continue to move towards the last touched point...
            var target = Vector2.Transform(lastTouchedPoint, inverseTransform);

            // ...quantized to the center of the nearest tile
            target = TileSpaceToWorldSpace(WorldSpaceToTileSpace(target)) + forestTiles.SpriteSize / 2;

            var moveOffset = target - wizardPosition;

            if (moveOffset.Length() < moveSpeed)
            {
                // we're close enough
                wizardPosition = target;
                return;
            }

            var moveDir = Vector2.Normalize(moveOffset);

            // Update the wizard's direction based on the move direction.
            // This will pick a different set of sprites so that it looks like
            // he's facing that direction.
            var angle = (float)Math.Atan2(moveDir.Y, moveDir.X);
            wizardDirection = GetDirection(angle);

            // Figure out the new position, clamped to inside the map
            var newPos = wizardPosition + (moveDir * moveSpeed);
            newPos = Vector2.Clamp(newPos, Vector2.Zero, forestTiles.SpriteSize * new Vector2(mapWidth, mapHeight));

            // If the new position hits a collision obstacle then the
            // wizard can't move there.
            var tilePos = WorldSpaceToTileSpace(newPos);

            int newColumn = (int)tilePos.X;
            int newRow = (int)tilePos.Y;
            int newIndex = (newRow * mapWidth) + newColumn;

            if (collisionLayer[newIndex] == 1)
                return;

            // Finally, set the new position.
            wizardPosition = newPos;
        }

        Vector2 WorldSpaceToTileSpace(Vector2 worldSpace)
        {
            var p = worldSpace / forestTiles.SpriteSize;
            p.X = (float)Math.Round(p.X - 0.5f);
            p.Y = (float)Math.Round(p.Y - 0.5f);
            return p;
        }

        Vector2 TileSpaceToWorldSpace(Vector2 tileSpace)
        {
            return tileSpace * forestTiles.SpriteSize;
        }

        static Direction GetDirection(double angle)
        {
            while (angle < 0)
                angle += Math.PI * 2;

            double bestDirectionScore = double.MaxValue;
            Direction bestDirection = Direction.Down;

            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                var directionAngle = directionAngles[(int)direction];

                var score = Math.Abs(directionAngle - angle);

                if (score < bestDirectionScore)
                {
                    bestDirectionScore = score;
                    bestDirection = direction;
                }
            }

            return bestDirection;
        }

        void UpdateTransform(ICanvasAnimatedControl sender)
        {
            // Figure out the camera - we want the wizard to be in the center of the screen, but not so much that the map goes off the screen
            var mapSize = forestTiles.SpriteSize * new Vector2((float)mapWidth, (float)mapHeight);

            var screenSize = sender.Size.ToVector2();
            var screenCenter = screenSize / 2;

            var minOffset = Vector2.Zero;
            var maxOffset = mapSize - screenSize;

            var cameraOffset = wizardPosition - screenCenter;

            cameraOffset = Vector2.Clamp(cameraOffset, minOffset, maxOffset);

            transform = Matrix3x2.Identity;

            if (RotateAndScale)
            {
                var mu = (1 - Math.Cos(rotateAndScaleCounter * 0.01)) * 0.5;

                transform = transform * 
                    Matrix3x2.CreateTranslation(-wizardPosition) * 
                    Matrix3x2.CreateScale((float)(1.0f + mu * 0.75f)) * 
                    Matrix3x2.CreateRotation((float)(mu * 0.1f)) * 
                    Matrix3x2.CreateTranslation(wizardPosition);
            }

            transform = transform * Matrix3x2.CreateTranslation(-cameraOffset);
        }

        void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            if (!spriteBatchSupported)
            {
                args.DrawingSession.DrawText("This version of Windows does not support sprite batch, so this example is not available.",
                    new Rect(new Point(0, 0), sender.Size), Colors.White, new CanvasTextFormat()
                    {
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Center
                    });
                return;
            }

            args.DrawingSession.Transform = transform;

            var size = sender.Size.ToVector2();

            var options = ClampToSourceRect ? CanvasSpriteOptions.ClampToSourceRect : CanvasSpriteOptions.None;
            var interpolation = (CanvasImageInterpolation)Enum.Parse(typeof(CanvasImageInterpolation), InterpolationMode);

            using (var sb = args.DrawingSession.CreateSpriteBatch(CanvasSpriteSortMode.None, interpolation, options))
            {
                DrawLayer(sb, baseLayer);
                DrawLayer(sb, fringeLayer);
                DrawLayer(sb, objectLayer);

                SpriteSheet wizardSheet = touched ? wizardWalk : wizardIdle;
                wizardSheet.Draw(sb, wizardCycle + (int)wizardDirection * 6, wizardPosition, Vector4.One);
            }
        }

        void DrawLayer(CanvasSpriteBatch sb, int[] layer)
        {
            for (int i = 0; i < layer.Length; ++i)
            {
                DrawTile(sb, layer, i);
            }
        }

        void DrawTile(CanvasSpriteBatch sb, int[] layer, int index)
        {
            int row = index / mapWidth;
            int column = index % mapWidth;

            Vector4 tint = Vector4.One;

            if (TintSprites)
                tint = ((row + column) % 2 == 0) ? Vector4.One : new Vector4(2, 1, 1, 1);

            if (ShowCollision)
                tint = collisionLayer[index] == 0 ? Vector4.One : new Vector4(2, 0.5f, 0.5f, 1);

            forestTiles.Draw(sb, layer[index], forestTiles.SpriteSize * new Vector2(column, row), tint);
        }

        #region Data

        int mapWidth = 42;
        int mapHeight; // this is calculated in the constructor

        int[] baseLayer =
        {
          128, 128, 3, 4, 5, 128, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 128, 41, 41, 128, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
          128, 128, 3, 4, 5, 128, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 128, 128, 128, 128, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
          41, 41, 3, 4, 5, -1, 49, -1, -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 38, -1, -1, -1, 41, -1, -1, 41, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 41, 41,
          41, 41, 3, 4, 5, 18, 41, 35, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 35, 41, 18, 42, 35, 41, 41, 35, 35, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 35, 35, 42, 41,
          41, 41, 3, 4, 5, 41, 41, 41, 18, 35, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 18, 41, 42, 41, 35, 41, 35, 35, 41, 75, 76, 76, 80, 80, 76, 76, 74, 41, 35, 35, 42, 41,
          41, 41, 3, 4, 5, 18, 41, 35, 41, 18, 41, 41, 41, 41, 41, 41, 18, 41, 41, 41, 18, 41, 42, 41, 41, 41, 41, 18, 41, 91, 72, 18, 35, 35, 18, 73, 92, 41, 41, 35, 42, 41,
          41, 41, 3, 4, 5, 41, 47, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, -1, 35, 41, 41, 18, 41, 41, 81, 18, 41, 41, 41, 41, 18, 81, 41, 35, 41, 42, 41,
          41, 41, 3, 4, 5, 18, 48, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, -1, 41, 41, 41, 41, 18, 41, 81, 18, 35, 35, 35, 35, 18, 81, 41, 35, 41, 42, 41,
          41, 41, 3, 4, 5, 41, 41, 41, 41, 35, 41, 41, 41, 35, 41, 41, 41, 35, 41, 41, 41, 41, 35, 41, 41, 41, 41, 41, 41, 93, 74, 35, 35, 35, 35, 75, 94, 41, 41, 41, 42, 41,
          41, 41, 3, 4, 5, 18, 128, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 35, 35, 41, 73, 76, 76, 76, 76, 76, 76, 72, 41, 35, 35, 42, 41,
          41, 41, 3, 4, 5, 41, 18, 75, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 41, 35, 35, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 35, 35, 42, 75,
          41, 41, 5, 5, 5, 18, 128, 79, 95, 76, 95, 76, 95, 76, 95, 95, 95, 95, 76, 76, 95, 95, 95, 95, 95, 47, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 51, 79,
          41, 41, 41, 41, 41, 41, 41, 79, 95, 95, 76, 95, 95, 76, 76, 76, 95, 76, 76, 95, 76, 95, 95, 95, 95, 48, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 48, 79,
          79, 77, 77, 77, 77, 77, 79, 99, 95, 76, 76, 76, 95, 95, 95, 76, 95, 95, 95, 95, 95, 95, 76, 95, 95, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 95, 77, 79, 79, 99,
          79, 95, 95, 95, 95, 95, 76, 76, 76, 95, 76, 95, 95, 76, 76, 76, 76, 76, 76, 95, 76, 95, 95, 95, 95, 76, 95, 76, 95, 95, 76, 76, 76, 95, 76, 95, 95, 95, 95, 95, 95, 95,
          79, 76, 95, 95, 95, 76, 95, 95, 76, 95, 95, 76, 76, 95, 76, 76, 76, 95, 95, 76, 76, 76, 76, 95, 95, 76, 95, 95, 95, 95, 95, 95, 95, 95, 76, 95, 95, 95, 95, 95, 95, 95,
          79, 76, 95, 95, 95, 76, 96, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 79, 95, 95, 95, 95, 95, 95, 95,
          79, 76, 95, 95, 95, 76, 78, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 79, 95, 95, 95, 95, 95, 95, 95,
          79, 76, 95, 95, 95, 76, 78, 2, 41, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 41, 42, 79, 95, 95, 95, 95, 95, 95, 95,
          79, 76, 95, 95, 95, 76, 78, 2, 41, 2, 41, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 41, 42, 41, 42, 79, 79, 76, 95, 76, 76, 97, 95,
          79, 76, 76, 76, 76, 76, 72, 2, 41, 2, 41, 2, 41, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 41, 42, 41, 42, 41, 42, 76, 37, 38, 38, 38, 39, 79, 95,
          41, 41, 0, 1, 2, 41, 41, 2, 41, 2, 41, 2, 41, 2, 41, 2, -1, -1, -1, 38, 38, 38, 39, -1, -1, 2, 41, 42, 41, 42, 41, 42, 41, 42, 76, 2, 41, 41, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 18, 2, 41, 2, 41, 2, 41, 2, 41, 18, 18, 41, 41, 41, 18, 18, 41, 42, 41, 42, 41, 42, 41, 42, 41, 42, 76, 2, 41, 41, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 41, 2, 41, 2, 18, 2, 41, 2, 18, 2, 41, 16, 16, 16, 16, 16, 16, 16, 41, 42, 18, 42, 18, 42, 35, 42, 35, 42, 76, 2, 35, 35, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 41, 2, 41, 2, 41, 2, 18, 2, 16, 16, 16, 16, 16, 16, 16, 16, 16, 42, 18, 42, 35, 42, 41, 42, 41, 42, 76, 2, 41, 35, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 41, 2, 18, 2, 35, 2, 18, 2, 18, 2, 16, 16, 16, 16, 16, 16, 16, 16, 16, 42, 18, 42, 41, 42, 41, 42, 41, 42, 81, 40, 41, 41, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 35, 22, 2, 41, 2, 41, 2, 18, 2, 18, 2, 16, 16, 16, 41, 41, 41, 16, 16, 16, 42, 18, 42, 18, 42, 41, 42, 41, 42, 81, 40, 41, 35, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 41, 2, 41, 2, 35, 2, 18, 2, 41, 2, 18, 16, 16, 16, 41, 16, 16, 16, 18, 42, 41, 42, 41, 42, 41, 42, 41, 42, 81, 40, 35, 41, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 35, 2, 41, 2, 41, 2, 41, 2, 41, 18, 18, 16, 41, 16, 18, 18, 41, 42, 41, 42, 18, 42, 35, 42, 35, 42, 76, 2, 41, 41, 41, 42, 79, 95,
          41, 41, 3, 4, 5, 41, 41, 2, 41, 2, 18, 2, 41, 2, 41, 47, 41, 41, 41, 2, 2, 2, 41, 41, 41, -1, 41, 42, 41, 42, 41, 42, 41, 42, 76, 55, -1, -1, -1, 56, 79, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 35, 2, 41, 2, 41, 2, 41, 48, 41, 41, 41, -1, -1, -1, 41, 41, 41, -1, 41, 42, 41, 42, 41, 42, 41, 42, 93, 77, 77, 77, 77, 77, 99, 95,
          41, 41, 3, 4, 5, 35, 41, 2, 41, 2, 35, 2, 41, 2, 41, 18, 41, 18, 41, 16, 17, 16, 41, 18, 41, 18, 41, 42, 41, 42, 41, 42, 41, 42, 79, 95, 95, 76, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 35, 22, 2, 18, 2, 41, 2, 18, 47, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, -1, 18, 42, 35, 42, 41, 42, 79, 95, 95, 95, 76, 95, 95, 95,
          41, 41, 3, 4, 5, 35, 41, 2, 41, 2, 41, 2, 41, 48, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, -1, 41, 42, 41, 42, 41, 42, 79, 95, 76, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 41, 2, 18, 2, 35, 41, 41, 18, 41, 41, 16, 17, 16, 41, 35, 18, 41, 41, 41, 18, 41, 42, 41, 42, 35, 42, 79, 95, 95, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 41, 2, 35, 47, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, -1, 35, 42, 41, 42, 79, 76, 95, 95, 95, 95, 76, 95,
          41, 41, 3, 4, 5, 35, 22, 2, 18, 2, 41, 48, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, -1, 41, 42, 41, 42, 79, 95, 76, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 35, 41, 2, 41, 2, 41, 41, 41, 41, 35, 41, 41, 41, 35, 41, 41, 41, 35, 41, 16, 17, 16, 41, 41, 41, 41, 42, 41, 42, 79, 95, 95, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 18, 47, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, 35, 42, 79, 95, 95, 95, 95, 95, 76, 95,
          41, 41, 3, 4, 5, 35, 41, 2, 41, 48, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, 41, 42, 79, 76, 95, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 41, 22, 2, 41, 41, 41, 41, 16, 17, 16, 41, 18, 41, 18, 41, 41, 41, 41, 41, 41, 41, 18, 41, 18, 41, 41, 18, 41, 42, 79, 76, 76, 76, 76, 95, 76, 95,
          41, 41, 3, 4, 5, 41, 41, 47, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, 79, 95, 95, 76, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 35, 22, 48, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, -1, -1, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, -1, 79, 95, 95, 95, 95, 95, 95, 95,
          41, 41, 3, 4, 5, 41, 41, 35, 35, 35, 35, 41, 41, 35, 41, 35, 35, 35, 16, 16, 17, 16, 16, 41, 41, 35, 35, 41, 35, 35, 41, 35, 41, 41, 79, 79, 79, 79, 79, 79, 76, 76,
          41, 41, 6, 7, 8, 41, 41, 35, 41, 41, 35, 41, 41, 41, 41, 41, 41, 41, 16, 16, 17, 16, 16, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
          41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
          41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41
        };

        int[] fringeLayer =
        {
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 194, 195, 196, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          129, 130, -1, -1, -1, 126, 37, 38, 38, 38, 197, 198, 199, 209, 210, 211, 185, 186, 187, 38, 38, 38, 39, 126, 126, 37, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 39, -1,
          131, 132, -1, -1, -1, -1, 40, -1, -1, -1, 200, 201, 202, 212, 213, 214, 188, 189, 190, -1, -1, -1, 42, -1, -1, 40, 155, 156, 68, 64, 64, 64, 64, 64, 64, 64, 64, 69, 155, 156, -1, -1,
          129, 130, -1, -1, -1, -1, 40, -1, -1, -1, 203, 204, 205, 215, 216, 217, 191, 192, 193, -1, -1, -1, 42, -1, -1, 40, 159, 160, 66, -1, 89, 82, -1, -1, 82, 90, -1, 67, 159, 160, -1, -1,
          131, 132, -1, -1, -1, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, -1, 40, -1, -1, 66, -1, -1, -1, 155, 156, -1, -1, -1, 67, -1, -1, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 49, 49, 49, 49, 49, 49, 58, 59, 60, 49, 49, 49, 49, 49, 49, 51, -1, -1, 40, -1, -1, 66, -1, -1, -1, 157, 158, -1, -1, -1, 67, -1, -1, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 50, 50, 50, 50, 50, 50, 61, 62, 63, 50, 50, 50, 50, 50, 50, 52, -1, -1, 40, -1, -1, 66, -1, -1, 155, 156, 155, 156, -1, -1, 67, -1, -1, -1, -1,
          129, 130, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 40, -1, -1, 66, -1, -1, 159, 160, 159, 160, -1, -1, 67, -1, -1, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 40, 155, 156, 66, -1, 87, 82, 82, 82, 82, 88, -1, 67, 155, 156, -1, 64,
          129, 130, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 40, 159, 160, 70, 65, 65, 65, 65, 65, 65, 65, 65, 71, 159, 160, -1, -1,
          131, 132, 6, 7, 8, -1, -1, -1, -1, 108, -1, 108, -1, 112, -1, -1, -1, -1, 111, 109, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 249, 250, 251, -1, -1, -1,
          64, 64, 64, 64, 64, 64, 64, -1, -1, -1, 109, -1, -1, 111, 112, 112, -1, 113, 109, -1, 108, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 252, 253, 254, -1, 52, -1,
          75, -1, 249, 250, 251, -1, 77, -1, -1, 109, 111, 109, -1, -1, -1, 110, -1, -1, -1, -1, -1, -1, 113, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 252, 253, 254, 77, 77, -1,
          79, -1, 252, 253, 254, -1, 108, 113, 108, -1, 109, -1, -1, 113, 111, 113, 111, 110, 108, -1, 112, -1, -1, -1, -1, 113, -1, 108, -1, -1, 109, 109, 111, -1, 109, -1, 252, 253, 254, -1, 108, -1,
          79, 113, 252, 253, 254, 113, -1, -1, 111, -1, -1, 111, 109, -1, 112, 108, 112, -1, -1, 113, 111, 113, 108, -1, -1, 111, -1, -1, -1, -1, -1, -1, -1, -1, 108, -1, 252, 253, 254, 108, -1, -1,
          79, 112, 252, 253, 254, 112, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 97, -1, 252, 253, 254, -1, -1, -1,
          79, 112, 252, 253, 254, 112, -1, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 79, -1, 252, 253, 254, 108, -1, -1,
          79, 112, 252, 253, 254, 112, -1, 40, -1, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, -1, 42, 79, 108, 252, 253, 254, -1, -1, -1,
          79, 113, 252, 253, 254, 113, -1, 40, -1, 40, -1, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, -1, 42, -1, 42, 91, 76, 252, 253, 254, -1, -1, 108,
          73, -1, 252, 253, 254, -1, -1, 40, -1, 40, -1, 40, -1, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, -1, 42, -1, 42, -1, 42, 81, -1, 252, 253, 254, -1, -1, -1,
          129, 130, 255, 256, 257, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, -1, 42, -1, 42, -1, 42, -1, 42, 81, 40, 255, 256, 257, 42, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, 42, -1, 42, -1, 42, -1, 42, 81, 40, -1, -1, -1, 42, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, -1, 224, 225, 226, -1, -1, -1, 42, -1, 42, -1, 42, -1, 42, -1, 42, 81, 40, -1, -1, -1, 42, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, 234, -1, -1, 227, 228, 229, -1, -1, 234, 42, -1, 42, -1, 42, -1, 42, -1, 42, 81, 40, -1, -1, -1, 42, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, 235, -1, -1, 230, 231, 232, -1, -1, 235, 42, -1, 42, -1, 42, -1, 42, -1, 240, 241, 242, -1, -1, -1, 42, -1, 108,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, -1, 238, -1, 239, 239, 239, -1, 238, -1, 42, -1, 42, -1, 42, -1, 42, -1, 246, 247, 248, -1, -1, -1, 42, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, -1, -1, 239, -1, -1, -1, -1, 42, -1, 42, -1, 42, -1, 42, -1, 243, 244, 245, -1, -1, -1, 42, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, -1, -1, 239, -1, -1, -1, -1, 42, -1, 42, -1, 42, -1, 42, -1, 42, 81, 40, -1, -1, -1, 42, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, 49, 49, 49, 58, 59, 60, 49, 49, 49, 51, -1, 42, -1, 42, -1, 42, -1, 42, 81, -1, 57, 57, 57, -1, -1, 108,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, 50, 50, 50, 61, 62, 63, 50, 50, 50, 52, -1, 42, -1, 42, -1, 42, -1, 42, 93, -1, -1, -1, -1, -1, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, 42, -1, 42, -1, 42, 79, 108, -1, 111, -1, -1, 110, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, -1, 49, 49, 49, 49, 58, 59, 60, 49, 49, 49, 49, 49, 49, 51, -1, 42, -1, 42, -1, 42, 79, -1, -1, -1, 111, -1, 108, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, -1, 50, 50, 50, 50, 61, 62, 63, 50, 50, 50, 50, 50, 50, 52, -1, 42, -1, 42, -1, 42, 79, -1, 111, -1, -1, -1, -1, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, 42, -1, 42, 79, -1, -1, 111, 111, 108, 111, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, -1, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 58, 59, 60, 49, 49, 51, -1, 42, -1, 42, 79, 111, -1, 108, 110, -1, 112, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, 40, -1, -1, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 61, 62, 63, 50, 50, 52, -1, 42, -1, 42, 79, -1, 112, -1, 239, -1, -1, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, 42, 79, -1, 111, 239, 238, 239, 238, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, -1, 49, 49, 58, 59, 60, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 51, -1, 42, 79, -1, -1, -1, 239, 108, 113, -1,
          129, 130, -1, -1, -1, -1, -1, 40, -1, -1, 50, 50, 61, 62, 63, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 52, -1, 42, 79, 113, 108, 111, 108, 111, 108, -1,
          131, 132, -1, -1, -1, -1, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, 79, 111, 113, 111, 110, -1, 111, -1,
          129, 130, -1, -1, -1, -1, -1, -1, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 58, 59, 60, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 51, 79, -1, -1, 112, -1, -1, -1, -1,
          131, 132, -1, -1, -1, -1, -1, -1, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 61, 62, 63, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 52, 79, -1, -1, -1, -1, -1, -1, -1,
          129, 130, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 238, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 73, 76, 76, 76, 76, 76, 129, 130,
          131, 132, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 131, 132,
          129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130, 129, 130,
          131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132, 131, 132
        };

        int[] objectLayer =
        {
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 206, 207, 208, 182, 183, 184, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, 149, 150, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 149, 150, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 218, 219, 220, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 221, 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        };

        int[] collisionLayer =
        {
          1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
          1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
          1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0,
          1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0,
          1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1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